package com.bruce.demo.springbootstarter.config;

import com.bruce.demo.springbootstarter.anno.EnableDemo;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.Assert;

import java.util.Map;

/**
 * @author Lenovo
 */
public class DemoSelector implements ImportSelector {

    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        //获取注解上的属性
        Map<String, Object> annotationAttributes = annotationMetadata.getAnnotationAttributes(EnableDemo.class.getName());
        Assert.notNull(annotationAttributes, "annotationAttributes must not null");
        Boolean enable = (Boolean) annotationAttributes.getOrDefault("enable", true);
        if (enable) {
            return new String[]{DemoAutoConfig.class.getName()};
        } else {
            return new String[]{};
        }
    }

}
